import { Controller, Get, Post, Body, Query, Param } from '@nestjs/common';
import { CpuService } from './cpu.service';

// import { CreateCpuDto } from './dto/create-cpu.dto';
// import { UpdateCpuDto } from './dto/update-cpu.dto';

@Controller('cpu')
export class CpuController {
  constructor(private readonly cpuService: CpuService) {}

  @Post('/series')
  async createCpuSeries(@Body() body: any) {
    const { manufacturers, series } = body;
    return this.cpuService.createCpuSeries(manufacturers, series);
  }

  @Get('/series')
  async getCpuSeries(@Query() query: any) {
    const { manufacturers } = query;
    return this.cpuService.getCpuSeries(manufacturers);
  }

  @Post('/code')
  async createCpuCode(@Body() body: any) {
    const { manufacturers, series, code_name } = body;
    return this.cpuService.createCpuCode(manufacturers, series, code_name);
  }

  @Get('/code')
  async getCpuCode(@Query() query: any) {
    const { manufacturers, series } = query;
    // console.log(manufacturers, series);

    return this.cpuService.getCpuCode(manufacturers, series);
  }

  @Post('/cpuinfo')
  async createCpuInfo(@Body() body: any) {
    console.log(body);

    return this.cpuService.createCpuInfo(body);
  }

  @Get('/cpuinfo')
  async getCpuInfo(@Query() query: any) {
    //分页查询
    //添加查询条件

    //系列 series
    //插槽 socket_type
    //价格区间 price

    return this.cpuService.getCpuInfo(query);
  }

  @Get('/cpuinfo/:id')
  async getCpuInfoById(@Param('id') id: string) {
    return this.cpuService.getCpuInfoById(id);
  }

  //更新CPU信息
  @Post('/cpuinfo/:id')
  async updateCpuInfo(@Param('id') id: string, @Body() body: any) {
    return this.cpuService.updateCpuInfo(id, body);
  }

  //删除CPU信息
  @Post('/cpuinfo/delete/:id')
  async deleteCpuInfo(@Param('id') id: string) {
    return this.cpuService.deleteCpuInfo(id);
  }


  //请求全部数据
  @Get('/total')
  async getCpuInfoTotal() {
    return this.cpuService.getCpuInfoTotal();
  }
}
